package org.linlinjava.litemall.admin.web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.linlinjava.litemall.admin.annotation.RequiresPermissionsDesc;
import org.linlinjava.litemall.admin.service.AdminLiquorTopicService;
import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.IliquormallTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/admin/liquor/topic")
@Validated
public class AdminLiquorTopicController {
    private final Log logger = LogFactory.getLog(AdminLiquorTopicController.class);

    @Autowired
    private AdminLiquorTopicService adminLiquorTopicService;

    /**
     * 添加酒业资讯
     *
     * @param liquorTopic
     * @return
     */
    @RequiresPermissions("admin:goods:create")
    @RequiresPermissionsDesc(menu = {"资讯管理", "资讯列表"}, button = "添加")
    @PostMapping("/create")
    public Object create(@RequestBody IliquormallTopic liquorTopic) {
        return adminLiquorTopicService.create(liquorTopic);
    }

    /**
     * 删除酒业资讯
     *
     * @param liquorTopic
     * @return
     */
    @RequiresPermissions("admin:liquorTopic:delete")
    @RequiresPermissionsDesc(menu = {"资讯管理", "资讯列表"}, button = "删除")
    @PostMapping("/delete")
    public Object delete(@RequestBody IliquormallTopic liquorTopic) {
        return adminLiquorTopicService.delete(liquorTopic);
    }

    /**
     * 编辑商品
     *
     * @param liquorTopic
     * @return
     */
    @RequiresPermissions("admin:liquorTopic:update")
    @RequiresPermissionsDesc(menu = {"资讯管理", "资讯列表"}, button = "更新")
    @PostMapping("/update")
    public Object update(@RequestBody IliquormallTopic liquorTopic) {
        return adminLiquorTopicService.update(liquorTopic);
    }

    /**
     * 查询酒业资讯列表
     *
     * @param title
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @return
     */
    @RequiresPermissions("admin:liquorTopic:read")
    @RequiresPermissionsDesc(menu = {"咨询管理", "咨询列表"}, button = "查询")
    @GetMapping("/list")
    public Object list(String title,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "20") Integer limit,
                       @Sort @RequestParam(defaultValue = "add_time") String sort,
                       @Order @RequestParam(defaultValue = "desc") String order) {
        return adminLiquorTopicService.list(title, page, limit, sort, order);
    }

    /**
     * 资讯详情
     *
     * @param id
     * @return
     */
    @RequiresPermissions("admin:liquorTopic:read")
    @RequiresPermissionsDesc(menu = {"商品管理", "商品管理"}, button = "查看")
    @GetMapping("/detail")
    public Object detail(@NotNull Integer id) {
        return adminLiquorTopicService.detail(id);
    }


}
